package com.gmail.blackdog1987.carcare.network.request.builder;

import android.content.Context;

import com.gmail.blackdog1987.carcare.Constant;
import com.gmail.blackdog1987.carcare.db.dao.UserDao;
import com.gmail.blackdog1987.carcare.network.request.RequestBuilder;
import com.gmail.blackdog1987.carcare.util.DeviceUtils;
import com.gmail.blackdog1987.carcare.util.LogUtil;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class OrderCarRentRequestBuilder extends RequestBuilder {

	private static final String TAG = OrderCarRentRequestBuilder.class.getSimpleName();
	private String userid;
	private String name;
	private String phone;
	private String info;
	private String carid;
	private String days;
	
	@Override
	public RequestParams buildRquest() {
		RequestParams params = new RequestParams();
		params.put("userid", String.valueOf(new UserDao().getUser().id));
		params.put("name", name);
		params.put("phone", phone);
		params.put("info", info);
		params.put("carid", carid);
		params.put("days", days);
		return params;
	}
	public OrderCarRentRequestBuilder setUserid(String userid){
		this.userid = userid;
		return this;
	}
	public OrderCarRentRequestBuilder setDays(String days){
		this.days = days;
		return this;
	}
	public OrderCarRentRequestBuilder setName(String name){
		this.name = name;
		return this;
	}
	public OrderCarRentRequestBuilder setPhone(String phone){
		this.phone = phone;
		return this;
	}
	public OrderCarRentRequestBuilder setInfo(String info){
		this.info = info;
		return this;
	}
	
	public OrderCarRentRequestBuilder setCarid(String carid){
		this.carid = carid;
		return this;
	}

	@Override
	public void postJsonRequest(Context context, AsyncHttpResponseHandler handler) {

		RequestParams params = buildRquest();
		
		AsyncHttpClient client = new AsyncHttpClient();
		client.setTimeout(Constant.TIMEOUT);
		client.setUserAgent(DeviceUtils.OS.getName());
		
		client.post(Constant.Action.ORDER_CARRENT, params, handler);
		LogUtil.d(TAG, "post : " + params);
	}

}
